package com.game.springbootstart.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.game.springbootstart.DTO.GamesDTO;
import com.game.springbootstart.config.QueryPageParam;
import com.game.springbootstart.config.Result;
import com.game.springbootstart.entity.Games;
import com.game.springbootstart.service.IGamesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/game")
public class GameController {
    @Autowired
    private IGamesService gamesService;
    @GetMapping("/listId")
    public Result listGames(@RequestParam Long id){
        return Result.success(gamesService.listId(id));
    }
    @GetMapping("/list")
    public Result list() {
        return Result.success(gamesService.list());
    }
    @PostMapping("/listPage")
    public Result listPage(@RequestBody QueryPageParam query) {
        IPage<GamesDTO> result = gamesService.listPage(query);
        return Result.success(result.getRecords(), result.getTotal());
    }
    @PostMapping("/approve")
    public Result approveStatus(@RequestParam Long id){
        Games games = gamesService.getById(id);
        games.setStatus("上线");
        return Result.success(gamesService.updateById(games));
    }
    @PostMapping("/reject")
    public Result rejectStatus(@RequestParam Long id){
        Games games = gamesService.getById(id);
        games.setStatus("下架");
        return Result.success(gamesService.updateById(games));
    }
}
